#!/usr/bin/python
# -*- coding: UTF-8 -*-
from time import clock
from sys import getrecursionlimit, getsizeof

x = {0:0, 1:1}
Rlimit = getrecursionlimit()
def fibonacci ( n ):
  global x
  if ( n-len(x) > Rlimit/2 ):
    fibonacci( len(x) + Rlimit/2 )
  try:
    return x[n]
  except:
    x[n] = fibonacci ( n-1 ) + fibonacci ( n-2 )
    return x[n]

start = clock()

n = 80000
print fibonacci ( n )


print "Fibonacci(",n ,") calculated in", (clock() - start), "s with a", getsizeof(x), "bytes memory usage."
